package Java8实战._1_Lambda._1_筛选绿苹果;

import _17_函数式编程.Lambda.Apple;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class _1_筛选绿苹果 {

    public static void main(String[] args) {
        List<Apple> inventory = Arrays.asList(
                new Apple("red",150),
                new Apple("green",123),
                new Apple("green",189)
        );

        List<Apple> result;

        result = filterGreenApple(inventory);
        printAppleList(result);

        System.out.println("\n================分隔符========================\n");

        result = filterRedApple(inventory);
        printAppleList(result);
    }

    public static List<Apple> filterGreenApple(List<Apple> inventory){

        List<Apple> result = new ArrayList<>();
        for (Apple apple : inventory){
            if ("green".equals(apple.getColor())){
                result.add(apple);
            }
        }
        return result;
    }

    public static List<Apple> filterRedApple(List<Apple> inventory){

        List<Apple> result = new ArrayList<>();
        for (Apple apple : inventory){
            if("red".equals(apple.getColor())){
                result.add(apple);
            }
        }
        return result;
    }

    public static void printAppleList(List<Apple> list){
        for (Apple apple : list){
            System.out.println("苹果的颜色：" + apple.getColor() + "，苹果的重量：" + apple.getWeight());
        }
    }
}
